<template>
	<view class="ys">
		<view class="form">
			<uni-section title="房间订单" type="line">
				<view class="inputbox">
					<uni-data-select v-model="order_id" :localdata="orderRange" @change="changeOrder"></uni-data-select>
				</view>
			</uni-section>
			<uni-section :title="roleConf.staff+'列表'" type="line">
				<view class="inputbox">
					<uni-data-select v-model="staff_id" :localdata="staffRange"></uni-data-select>
				</view>
			</uni-section>
			<uni-section title="监督内容" type="line">
				<view class="inputbox">
					<uni-easyinput type="textarea" v-model="content" trim placeholder="监督内容"
						clearSize="20"></uni-easyinput>
				</view>
			</uni-section>
		</view>

		<button class="btn" @click="subWatch" :loading="loading" :disabled="loading">提交</button>
	</view>
</template>

<script>
	import {
		staffWatchOrder,
		subWatch
	} from "@/api/staff.js"
	export default {
		data() {
			return {
				order_id: '',
				orderRange: [],
				orderList: [],
				content: '',
				loading: false,
				staffRange: [],
				staff_id: ''
			}
		},
		onLoad() {
			this.staffWatchOrder()
		},
		methods: {
			staffWatchOrder() {
				staffWatchOrder().then(res => {
					if (res.code == 0) {
						this.orderList = res.data
						this.orderList.forEach((item, index) => {
							this.orderRange.push({
								value: item.id,
								text: `房间:【${item.room.name}】, 完成:${item.finish_time}`
							})
						})
					}
				})
			},
			changeOrder(e) {
				let i = this.orderList.findIndex(item => item.id == e)
				if (i > -1) {
					this.staffRange = []
					let staff = this.orderList[i].staff
					staff.forEach((item, index) => {
						this.staffRange.push({
							value: item.staff_id,
							text: `姓名【${item.staff.name}】, ${item.staff.phone}`
						})
					})
				}
			},
			subWatch() {
				let that = this
				if (this.order_id == '') {
					return uni.$showMsg('请选择房间订单')
				}
				if (this.staff_id == '') {
					return uni.$showMsg('请选择促销员')
				}
				if (this.content == '') {
					return uni.$showMsg('请输入监督内容')
				}
				that.loading = true
				subWatch({
					order_id: this.order_id,
					staff_id: this.staff_id,
					content: this.content
				}).then(res => {
					uni.$showMsg(res.msg)
					if (res.code == 0) {
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					} else {
						that.loading = false
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		.inputbox {
			width: 96%;
			margin: 0px auto;
		}

		.form {
			padding-bottom: 15px;
			background: #fff;
		}

		.btn {
			button {
				color: #fff;
				font-size: 16px;
				letter-spacing: 1px;
				margin: 30px auto;
				width: 96%;
			}
		}
	}
</style>